package com.csx.governance.traffic.core;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cuisongxu
 * @date 2023/2/23 15:28
 */
public class TransportableAttributes {

    private static final ThreadLocal<Map<String, String>> TRANSPORTABLE_ATTRIBUTES = ThreadLocal.withInitial(HashMap::new);

    private TransportableAttributes(){}

    public static void setAttribute(String key, String value) {
        Map<String, String> attributes = TRANSPORTABLE_ATTRIBUTES.get();
        attributes.put(key, value);
    }

    public static String getAttribute(String key) {
        return TRANSPORTABLE_ATTRIBUTES.get().get(key);
    }

    public static void removeAttribute(String key) {
        TRANSPORTABLE_ATTRIBUTES.get().remove(key);
    }

    public static Map<String, String> getAttributes() {
        return TRANSPORTABLE_ATTRIBUTES.get();
    }

    public static void clear() {
        TRANSPORTABLE_ATTRIBUTES.remove();
    }
}
